﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OA.DBUtility;
using OA.Model;

namespace OA.Manager
{
    public class EmployeeEducationMappingManager
    {
            private SqlService<EmployeeEducationMappingInfo> _sqlService = null;

            public EmployeeEducationMappingManager()
            {
                _sqlService = new SqlService<EmployeeEducationMappingInfo>();
            }

        #region  Method

        /// <summary>
        /// 插入员工在职教育详情
        /// </summary>
        /// <param name="employeeEducation"> </param>
        /// <returns></returns>
        public bool InsertEmployeeEducationMappingInfo(EmployeeEducationMappingInfo employeeEducation)
        {
            if (employeeEducation == null) throw new ArgumentNullException("employeeEducation");
            return _sqlService.SaveEntity(employeeEducation);
        }

        /// <summary>
        ///根据条件得到员工在职教育明细
        /// </summary>
        ///<returns></returns>
        public EmployeeEducationMappingInfo GetEmployeeEducationMappingInfo(string filter)
        {
            string sql = "SELECT * FROM dbo.EmployeeEducationMapping WHERE 1=1 AND " + filter;
            return _sqlService.GetSingleBySqlString(sql);
        }

        /// <summary>
        /// 判断该员工在职教育信息是否存在
        /// </summary>
        /// <param name="filter"> </param>
        /// <returns></returns>
        public bool IsEmployeeEducationMappingInfo(string filter)
        {
            object value = _sqlService.ExecuteScalar("SELECT * FROM dbo.EmployeeEducationMapping WHERE 1=1 AND" + filter);
            if (value != null)
            {
                int count;
                if (int.TryParse(value.ToString(), out count) && count > 0)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 根据指定的字段更新，字段名是数据库中对应的名称
        /// </summary>
        /// <param name="employeeEducation"> </param>
        /// <param name="needUpdateFields"></param>
        /// <returns></returns>
        public bool UpdateEmployeeEducationMappingInfo(EmployeeEducationMappingInfo employeeEducation, List<string> needUpdateFields, string filter)
        {
            return _sqlService.UpdateByFieldsFilter(employeeEducation, needUpdateFields, filter);
        }

        /// <summary>
        /// 删除在职教育详情
        /// </summary>
        /// <param name="filter"> </param>
        /// <returns></returns>
        public bool DeleteEmployeeEducationMappingInfo(string filter)
        {
            return _sqlService.DeleteEntity("EmployeeEducationMapping", filter);
        }
        #endregion  Method
    }
}
